var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputValue:''

  },

  onLoad: function (options) {
    var store_id = wx.getStorageSync("store_id");
    var account_id = wx.getStorageSync("account_id");
    var id = options.id;
    console.log(store_id)
    if(!store_id || !account_id){
      app.showToast("请登录小程序")
      wx.navigateBack();
    }else{
      this.setData({
        store_id:wx.getStorageSync("store_id"),
        account_id:wx.getStorageSync("account_id"),
        stored_id:id
      })
      this.getStoredInfo();
    }
  },

  getStoredInfo:function(){
    var t = this;
    app.visit("account/getStoredInfo", {
      store_id:t.data.store_id,
      account_id:t.data.account_id,
      stored_id:t.data.stored_id,
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        t.setData({
          info:c.data.info,
          stored_log:c.data.stored_log
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  setPrice:function(e){
    var inputValue = e.detail.value;
    this.setData({
      inputValue: inputValue,
    })
  },

  ljchongzhi:function(){
    var t = this;
    var inputValue = t.data.inputValue;
    if (inputValue == 0 || !inputValue) {
      app.myToast("请输入充值金额")
    }else if (!(/(^[0-9]+(.[0-9]{1,2})?$)/.test(inputValue))) {
      app.myToast("充值金额只能输入数字！")
    }else{
      app.visit("account/setUserStoredInfo", {
        store_id:t.data.store_id,
        sh_id:t.data.account_id,
        stored_id:t.data.stored_id,
        user_id:t.data.info.user_id,
        price:inputValue,
      }, "", function(c) {
        console.log(c)
        if(0 == c.code){
          app.showToast("充值成功")
          t.getStoredInfo();
          t.setData({
            inputValue:''
          })
        }else{
          app.showToast(c.msg)
        }
      })
    }
  },

  BeginSearch: function (e) {
    this.setData({
      inputValue: '',
    })
  } 
})